﻿using System;
using System.Data;
using System.Data.Entity;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Linq.Expressions.Internal;
using System.Web;
using System.Web.Mvc;
using DiarySocial.Filters;
using DiarySocial.Models;
using DiarySocial.ViewModels;
using WebMatrix.WebData;

namespace DiarySocial.Controllers
{
    [Authorize]
    [InitializeSimpleMembership]
    public class HomeController : Controller
    {
        private DiaryEnties db = new DiaryEnties();
        [Authorize]
        public ActionResult Index()
        {
            var id = WebSecurity.GetUserId(User.Identity.Name);
            var diaries = db.GetDiariesForHome(id);
            var model = new HomeWithTimeLineVM()
            {
                Diaries = diaries.ToList()
            };
            return View(model);
        }
        
        [AllowAnonymous]
        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }
        [AllowAnonymous]
        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
        [Authorize]
        public ActionResult LockMe()
        {
            if (Request.IsAjaxRequest())
            {
                return PartialView("_LockMe");
            }
            throw new HttpException(404, "HTTP/1.1 404 Not Found");
        }
        public ActionResult Widgets()
        {
            return View();
        }
    }
}